import re,os,shutil
from curl_cffi import requests
if os.path.exists('static/彼岸图'):
    shutil.rmtree('static/彼岸图')
    os.mkdir('static/彼岸图')
else:
    os.mkdir('static/彼岸图')

url = 'https://pic.netbian.com'

headers = {
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
'referer': 'https://pic.netbian.com/'
}
response = requests.get(url,headers=headers)

response_text = response.content.decode('gbk')
pattern = r'<a href="([^"]*)" title="([^"]*)"[^>]*>\s*<span>\s*<img src="([^"]*)"'
result = re.findall(pattern, response_text, re.S)
for item in result:
    img_href = item[0]
    title = item[1]
    img_url = item[2]
    img_detail_url = url + img_url
    # print(img_url, title, img_href)
    # print(img_detail_url)


    with open(f'static/彼岸图/{title}.jpg','wb')as f:
        img_response = requests.get(img_detail_url,headers=headers)
        # print(img_response.content)
        f.write(img_response.content)







